export function retainDecimals(price, extent) {
  const index = String(price).indexOf('.') + 1 // 获取小数点的位
  const count = String(price).length - index // 获取小数点后的个数
  if (index) {
    if (count === 1) {
      price += '0'
    } else if (count > extent) {
      price.toFixed(extent)
    }
  } else {
    price += '.00'
  }
  if (!Number(price)) {
    price = '0.00'
  }
  return price
}

/**
 * 遍历视频与图片
 */
export function isPictures(pictures) {
  const picturesArr = pictures.split(',')
  const picturesObj = {
    video: '',
    image: []
  }
  // 后缀获取
  let suffix = ''
  let result = ''
  try {
    const flieArr = picturesArr[0].split('.')
    suffix = flieArr[flieArr.length - 1]
  } catch (err) {
    suffix = ''
  }
  // 匹配 视频
  const videolist = ['mp4', 'm2v', 'mkv', 'rmvb', 'wmv', 'avi', 'flv', 'mov', 'm4v']
  result = videolist.find(item => item === suffix)
  if (result) {
    picturesObj.video = picturesArr[0]
    if (picturesArr.length > 1) {
      picturesArr.forEach((child, index) => {
        if (index > 0) {
          picturesObj.image = [
            ...picturesObj.image,
            child
          ]
        }
      })
    }
  } else {
    picturesObj.image = picturesArr
  }
  return picturesObj
}
